#
# uCsim f8.src/Makefile
#
# (c) Drotos Daniel, Talker Bt. 1997,2022
#

# tool name
TN		= f8

STARTYEAR	= 1997

SHELL		= /bin/sh
CXX		= @CXX@
CPP		= @CPP@
CXXCPP		= @CXXCPP@
RANLIB		= @RANLIB@
INSTALL		= @INSTALL@
STRIP		= @STRIP@
MAKEDEP         = @MAKEDEP@

top_builddir	= @top_builddir@
top_srcdir	= @top_srcdir@

transform	= @program_transform_name@

DEFS            = $(subs -DHAVE_CONFIG_H,,@DEFS@)
CPPFLAGS        = @CPPFLAGS@ -I$(srcdir) -I$(top_srcdir) -I$(top_builddir) \
		  -I$(top_srcdir)/cmd.src -I$(top_srcdir)/sim.src \
		  -I$(top_srcdir)/gui.src
CFLAGS          = @WALL_FLAG@ @CFLAGS@
CXXFLAGS        = @WALL_FLAG@ @CXXFLAGS@
LDFLAGS         = @LDFLAGS@
PICOPT		= @PICOPT@
SHAREDLIB	= @SHAREDLIB@
EXEEXT		= @EXEEXT@

LIBS		= -L$(top_builddir) -lsim -lucsimutil -lguiucsim -lcmd -lsim @LIBS@
DL		= @DL@
dl_ok		= @dl_ok@

prefix          = @prefix@
exec_prefix     = @exec_prefix@
bindir          = @bindir@
libdir          = @libdir@
datadir         = @datadir@
datarootdir     = @datarootdir@
includedir      = @includedir@
mandir          = @mandir@
man1dir         = $(mandir)/man1
man2dir         = $(mandir)/man2
infodir         = @infodir@
srcdir          = @srcdir@
VPATH           = @srcdir@

OBJECTS_SHARED	= sim$(TN).o $(TN).o glob.o disass.o \
		  inst.o ialu.o ibranch.o imove.o
#		  irq.o port10.o

OBJECTS_EXE	= s$(TN).o
OBJECTS		= $(OBJECTS_SHARED) $(OBJECTS_EXE)

# short/long exe and lib name
SEN		= s$(TN)$(EXEEXT)
LEN		= ucsim_$(TN)$(EXEEXT)
LENOLD		= ucsim_mcs6502$(EXEEXT)

SONAME		= libucsim_$(TN).so

enable_dlso	= @enable_dlso@
dlso_ok		= @dlso_ok@

F8ASM	=
TEST_OBJ	= 


# Compiling entire program or any subproject
# ------------------------------------------
all: checkconf otherlibs $(TN).src


# Compiling and installing everything and running test
# ---------------------------------------------------
install: all installdirs install_shared_lib
	$(INSTALL) $(LEN) $(DESTDIR)$(bindir)/$(LEN)
	$(STRIP) $(DESTDIR)$(bindir)/$(LEN)
	rm -f $(DESTDIR)$(bindir)/$(SEN)
	rm -f $(DESTDIR)$(bindir)/$(LENOLD)


# Deleting all the installed files
# --------------------------------
uninstall:
	rm -f $(DESTDIR)$(bindir)/$(SEN)
	rm -f $(DESTDIR)$(bindir)/$(LEN)
	rm -f $(DESTDIR)$(bindir)/$(LENOLD)
	rm -f $(DESTDIR)$(libdir)/$(SONAME)


# Performing self-test
# --------------------
check: $(TEST_OBJ)

.PHONY:	test baseline
test:
	@$(MAKE) --no-print-directory -C test

baseline:
	@$(MAKE) --no-print-directory -C test baseline


# Performing installation test
# ----------------------------
installcheck:


# Creating installation directories
# ---------------------------------
installdirs:
	test -d $(DESTDIR)$(bindir) || $(INSTALL) -d $(DESTDIR)$(bindir)


# Creating dependencies
# ---------------------
dep: Makefile.dep

Makefile.dep: $(srcdir)/*.cc $(srcdir)/*.h
	$(MAKEDEP) $(CPPFLAGS) $(filter %.cc,$^) >Makefile.dep

-include Makefile.dep
include $(srcdir)/clean.mk

# My rules
# --------
.SUFFIXES: .asm .hex

$(TN).src: $(LEN) shared_lib

$(LEN): $(OBJECTS) $(top_builddir)/libcmd.a $(top_builddir)/libguiucsim.a $(top_builddir)/libsim.a $(top_builddir)/libucsimutil.a
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@

#$(LEN): $(SEN)
#	cp $< $@

#$(LENOLD): $(SEN)
#	cp $< $@

ifeq ($(dlso_ok),yes)
shared_lib: $(top_builddir)/$(SONAME)
install_shared_lib: shared_lib
	test -d $(DESTDIR)$(libdir) || $(INSTALL) -d $(DESTDIR)$(libdir)
	$(INSTALL) $(top_builddir)/$(SONAME) $(DESTDIR)$(libdir)/$(SONAME)
else
shared_lib:
	@$(top_srcdir)/mkecho $(top_builddir) "No $(TN) shared lib made."
	@$(top_srcdir)/mkecho $(top_builddir) "(SHAREDLIB="$(SHAREDLIB)",dl_ok="$(dl_ok)",enable_dlso="$(enable_dlso)")"
install_shared_lib:
endif

$(top_builddir)/$(SONAME): $(OBJECTS_SHARED)
	$(CXX) -shared $(LDFLAGS) $(OBJECTS_SHARED) -o $@

otherlibs: $(top_builddir)/libcmd.a $(top_builddir)/libguiucsim.a $(top_builddir)/libsim.a $(top_builddir)/libucsimutil.a

$(top_builddir)/libcmd.a:
	$(MAKE) -C $(top_builddir)/cmd.src all

$(top_builddir)/libguiucsim.a:
	$(MAKE) -C $(top_builddir)/gui.src checkconf ucsim_lib

$(top_builddir)/libsim.a:
	$(MAKE) -C $(top_builddir)/sim.src all

$(top_builddir)/libucsimutil.a:
	$(MAKE) -C $(top_builddir) -f main.mk

.cc.o:
	$(CXX) $(CXXFLAGS) $(PICOPT) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@

.asm.hex:
	$(F8ASM) -l $< -o $@ -e $<.lst


# Remaking configuration
# ----------------------
checkconf:
	@if [ -f $(top_builddir)/devel ]; then\
	  $(MAKE) -C $(top_builddir) -f conf.mk srcdir="$(srcdir)" top_builddir="$(top_builddir)" freshconf;\
	fi

# End of f8.src/Makefile.in
